﻿var SPListExtractor = (function () {
    function SPListExtractor() {
        document.title += " SPListExtractor is active";
    }
    SPListExtractor.getFirst = function (arr) {
        for (var prop in arr)
            if (arr.propertyIsEnumerable(prop))
                return prop;
    };

    SPListExtractor.isFunction = function (functionToCheck) {
        var getType = {};
        return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
    };

    SPListExtractor.validateEmail = function (email) {
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    };

    //#region Dynamic loading
    SPListExtractor.loadjsfile = function (filename) {
        var fileref = document.createElement('script');
        fileref.setAttribute("type", "text/javascript");
        fileref.setAttribute("src", filename);
        if (typeof fileref != "undefined")
            document.getElementsByTagName("head")[0].appendChild(fileref);
    };

    SPListExtractor.loadScript = function (url, callback) {
        var script = document.createElement("script");
        script.type = "text/javascript";

        if (script.readyState) {
            script.onreadystatechange = function () {
                if (script.readyState == "loaded" || script.readyState == "complete") {
                    script.onreadystatechange = null;
                    callback();
                }
            };
        } else {
            script.onload = function () {
                callback();
            };
        }

        script.src = url;
        document.getElementsByTagName("head")[0].appendChild(script);
    };

    SPListExtractor.loadcssfile = function (filename) {
        if (document.createStyleSheet) {
            document.createStyleSheet(filename);
        } else {
            var fileref = document.createElement("link");
            fileref.setAttribute("rel", "stylesheet");
            fileref.setAttribute("type", "text/css");
            fileref.setAttribute("href", filename);
            if (typeof fileref != "undefined")
                document.getElementsByTagName("head")[0].appendChild(fileref);
        }
    };
    return SPListExtractor;
})();

//#region Global initializations
if (typeof _spPageContextInfo != "undefined" && _spPageContextInfo != null) {
    RegisterModuleInit(_spPageContextInfo.siteServerRelativeUrl + '/_catalogs/masterpage/customjavascript/SPListExtractor.core.js', SPListExtractor);

    SPListExtractor();
} else {
    _spBodyOnLoadFunctionNames.push("SPListExtractor");
}
